﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contactusform.common
{
    public class Utils
    {
        /// <summary>
        /// Gets a key as a string from the WebConfig AppSettings section 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string GetAppSettingAsString(string key)
        {
            var reader = new AppSettingsReader();
            return reader.GetValue(key, typeof(string)) as string;
        }

        /// <summary>
        /// Gets a key as an int from the WebConfig AppSettings section 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static int GetAppSettingAsInt(string key)
        {
            var reader = new AppSettingsReader();
            return Convert.ToInt32(reader.GetValue(key, typeof(Int32)));

        }

        /// <summary>
        /// Gets the OpeningTime value and with it creates a TimeSpan.
        /// </summary>
        public static TimeSpan OpeningTime
        {
            get
            {
                return TimeSpan.ParseExact(GetAppSettingAsString("OpeningTime"), "hh\\:mm\\:ss", CultureInfo.InvariantCulture);

            }
        }

        /// <summary>
        /// Gets the ClosingTime value and with it creates a TimeSpan.
        /// </summary>
        public static TimeSpan ClosingTime
        {
            get
            {
                return TimeSpan.ParseExact(GetAppSettingAsString("ClosingTime"), "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
            }
        }

    }

}
